package com.example.demo.common;

import com.example.demo.entity.User;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

public class UserSessionUtils {
    // 获取当前登录用户的信息
    public static User getUser(HttpServletRequest request) {
        HttpSession session = request.getSession(false);
        if (session != null) {
            return (User) session.getAttribute(AppConstant.SESSION_USER_KEY);
        }
        return null;
    }

    public static Integer getUserId(HttpServletRequest request) {
        HttpSession session = request.getSession(false);
        User user = (User) session.getAttribute(AppConstant.SESSION_USER_KEY);
        return user.getId();
    }
}
